import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';


class ImageUtils {
  static const String rootPath = 'assets/icons';
  static const String imagesPath = 'assets/images';

  static Image imageAsset(String icon) => Image.asset(rootPath + icon);

  static Image imageNet(String url) => Image.network(url);

  static String getImgPath(String name, {ImageFormat format = ImageFormat.png}) {
    return 'assets/images/$name.${format.value}';
  }

  static ImageProvider getImageProvider(String? imageUrl, {String holderImg = 'none'}) {
    if (imageUrl == null || imageUrl.isEmpty) {
      return AssetImage(getImgPath(holderImg));
    }
    return CachedNetworkImageProvider(imageUrl);
  }
}


enum ImageFormat {
  png,
  jpg,
  gif,
  webp
}

extension ImageFormatExtension on ImageFormat {
  String get value => ['png', 'jpg', 'gif', 'webp'][index];
}